//
//  UIImage+TYScale.m
//  Somago
//
//  Created by 谢航宇_WORK on 2021/10/22.
//  Copyright © 2021 juniu. All rights reserved.
//

#import "UIImage+TYScale.h"

@implementation UIImage (TYScale)
- (UIImage *)scaleImage {
    //自适应新尺寸
    CGSize newSize = CGSizeMake(self.size.width * ([UIScreen mainScreen].bounds.size.width/375.0), self.size.height * ([UIScreen mainScreen].bounds.size.width/375.0));
    UIGraphicsBeginImageContextWithOptions(newSize, NO, self.scale);
    [self drawInRect:CGRectMake(0,0,newSize.width,newSize.height)];
    UIImage* newImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return newImage;
}

- (UIImage *)scaleImageToWidth:(CGFloat)width {
    //新比例
    CGFloat scale = width/self.size.width;
    //自适应新尺寸
    CGSize newSize = CGSizeMake(self.size.width * scale, self.size.height * scale);
    UIGraphicsBeginImageContextWithOptions(newSize, NO, self.scale);
    [self drawInRect:CGRectMake(0,0,newSize.width,newSize.height)];
    UIImage* newImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return newImage;
}

@end
